<!--suppress ALL -->
<template>
  <div class="mod-menu">
    <div>
    <el-form :inline="true" :model="queryForm.data" class="demo-form-inline">
      <el-form-item>
        <el-input clearable v-model="queryForm.data.name" placeholder="菜单名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getDataList()" icon="el-icon-search">查询</el-button>
      </el-form-item>
    </el-form>
      <el-button type="primary" size="small" icon="el-icon-plus" @click="$router.push({ name: 'sys-menu-add-or-update'})">添加</el-button>
  </div>
  <hr>

    <el-table
      :data="dataList"
      border
      style="width: 100%;"
    >
      <el-table-column
        type="index"
        header-align="center"
        align="center"
        width="80"
        label="序号"
      >
      </el-table-column>
      <table-tree-column
        prop="name"
        header-align="center"
        treeKey="id"
        width="300"
        label="名称">
      </table-tree-column>
      <el-table-column
        header-align="center"
        align="center"
        width="200"
        label="图标">
        <template slot-scope="scope">
          <icon-svg :name="scope.row.icon || ''"></icon-svg>
        </template>
      </el-table-column>
      <el-table-column
        prop="sort"
        header-align="center"
        align="center"
        label="排序号">
      </el-table-column>
      <el-table-column
        prop="href"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="菜单URL">
      </el-table-column>
      <el-table-column
        prop="permission"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="授权标识">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="200"
        label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="small"
                     @click="$router.push({name:'sys-menu-add-or-update',params:{id:scope.row.id}})"
                     icon="el-icon-edit">修改
          </el-button>
          <el-button type="danger" size="small" @click="deleteHandle(scope.row)"
                     icon="el-icon-delete">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import TableTreeColumn from '@/components/table-tree-column'
  import {treeDataTranslate} from '@/utils'

  export default {
    data() {
      return {
        dataList: [],
        dataListLoading: false,
        queryForm: {
          data: {
            name: ''
          }
        }
      }
    },
    components: {
      TableTreeColumn
    },
    created() {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/sysMenu/findAllMenu'),
          method: 'get',
          params: this.$http.adornParams({name: this.queryForm.data.name})
        }).then(({data}) => {
          this.dataList = data
          // console.log(this.dataList)
          this.dataListLoading = false
        })
      },
      // 删除
      deleteHandle(row) {
        this.$confirm(`确定对[菜单=${row.name}]进行[删除]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl(`/sysMenu/delete`),
            method: 'get',
            params: this.$http.adornParams({
              id: row.id
            })
          }).then(() => {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }

    }
  }
</script>

<style scoped>

</style>
